package com.atguigu.upp.utils;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.spark.sql.SparkSession;

import java.io.IOException;
import java.io.InputStream;


public class UPPUtil
{
    public static SqlSessionFactory getSqlSessionFactoryByConfig(String config) throws IOException {
        InputStream inputStream = Resources.getResourceAsStream(config);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        return sqlSessionFactory;
    }
    
    public static SparkSession getSparkSession(String appName){

        SparkSession sparkSession = SparkSession.builder()
                                             .master(PropertiesUtil.getProperty("masterUrl"))
                                             .appName(appName)
                                             .enableHiveSupport()  //开启支持读写hive
                                             .getOrCreate();

        return sparkSession;
        
    }
}
